package com.hongxun.design.ui.statisticsmap.pieview;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.hongxun.design.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zerdoor_pc on 2016/6/29.
 */
public class MPieChartView extends LinearLayout {
    private Context mContext = null;
    PieChartView piegraphView;
    ListView piegraphview_list;

    public MPieChartView(Context context) {
        super(context);
        this.mContext = context;

    }

    public MPieChartView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;

    }

    public MPieChartView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.mContext = context;


    }


    @Override
    protected void onFinishInflate() {
        piegraphView = (PieChartView) findViewById(R.id.piegraphview);
        piegraphview_list = (ListView) findViewById(R.id.piegraphview_list);
        super.onFinishInflate();
    }

    MPiewChartAdapter adapter;
    List<PieItemBean> listData=new ArrayList<>();
    public void setStart(List<PieItemBean> items) {
        listData.clear();
        listData.addAll(items);

        if (piegraphView != null && piegraphview_list != null) {
            piegraphView.setPieItems(listData);
            if (adapter==null){
                adapter = new MPiewChartAdapter(mContext, listData);
                piegraphview_list.setAdapter(adapter);
            }else{
                adapter.notifyDataSetChanged();
            }
        }
    }

    public void update(){
        if (adapter!=null){
            adapter.notifyDataSetChanged();
            piegraphView.setPieItems(listData);
        }

    }
}
